export default {
  namespaced: true,
  state: {
    updateView: false, // 更新视图
    keepAlive: [], // 需缓存的页面
    keepMenu: [], // 显示菜单的页面
    menuActive: '11111' // 激活的底部菜单项
  },
  getters: {
    updateView: (state) => state.updateView,
    keepAlive: (state) => state.keepAlive,
    keepMenu: (state) => state.keepMenu,
    menuActive: (state) => state.menuActive
  },
  mutations: {
    setUpdateView: (state) => {
      state.updateView = !state.updateView;
    },
    setKeepAlive: (state, value) => (state.keepAlive = value),
    addKeepAlive: (state, name) => {
      if (!name) return false;
      if (!state.keepAlive.includes(name)) {
        state.keepAlive.push(name);
      }
    },
    minusKeepAlive: (state, name) => {
      if (!name) return false;
      if (state.keepAlive.includes(name)) {
        state.keepAlive.splice(state.keepAlive.indexOf(name), 1);
      }
    },
    addKeepMenu: (state, path) => {
      if (!path) return false;
      if (!state.keepMenu.includes(path)) {
        state.keepMenu.push(path);
      }
    },
    setMenuActive: (state, name) => (state.menuActive = name)
  },
  actions: {}
};
